// extern crate rocket;
use remolder::models::Storage;
use remolder::routes;
use rocket::fairing::AdHoc;
use rocket::fs::FileServer;
use rocket::{Build, Rocket};
use rocket_dyn_templates::Template;

fn rocket() -> Rocket<Build> {
    rocket::build()
        .attach(Template::fairing())
        .attach(AdHoc::on_ignite("Manage State", |rocket| async move {
            let storage = rocket
                .figment()
                .extract_inner::<Storage>("storage")
                .unwrap();
            rocket.manage(storage)
        }))
        .mount("/", routes::index::routes())
        .mount("/", routes::download::routes())
        .mount("/", routes::upload::routes())
        .mount("/assets", FileServer::from("assets"))
}

#[rocket::main]
async fn main() -> Result<(), rocket::Error> {
    rocket().launch().await
}
